package imp

import (
	"bgs/cache/redisImp"
	"bgs/conf"
	"bgs/db"
	"bgs/grpc/client"
	afterSaleGrpc "bgs/grpc/gen/service/after_sale"
	afterSaleService "bgs/service/afterSale"
	ledgerService "bgs/service/ledger"
	orderService "bgs/service/order"
	paymentService "bgs/service/payment"
	"bgs/util"
	wxpMinaService "bgs/wxp/mina"
	"context"

	"go.uber.org/zap"
)

// AfterSaleAPIService :grpc server proxy of after_sale
type AfterSaleAPIService struct {
	dao  *db.PgDao
	slog *zap.SugaredLogger
	afterSaleGrpc.AfterSaleOpServer
	cacher           *cache.Adapter
	afterSaleService *afterSaleService.AfterSaleServiceImp
	ledgerService    *ledgerService.LedgerServiceImp
	orderService     *orderService.OrderServiceImp
	paymentService   *paymentService.PaymentServiceImp
	wxpMinaService   *wxpMinaService.MinaServiceImp
}

// NewAfterSaleAPIService initialization
func NewAfterSaleAPIService(
	pgdao *db.PgDao,
	slog *zap.SugaredLogger,
	vars *conf.VarsSection,
	proxy *client.GrpcClientProxy,
	adp *cache.Adapter,
	afterSaleService *afterSaleService.AfterSaleServiceImp,
	ledgerService *ledgerService.LedgerServiceImp,
	orderService *orderService.OrderServiceImp,
	paymentService *paymentService.PaymentServiceImp,
	wxpMinaService *wxpMinaService.MinaServiceImp,
) *AfterSaleAPIService {
	return &AfterSaleAPIService{
		dao:              pgdao,
		slog:             slog.With("module", "AfterSaleAPIService"),
		cacher:           adp,
		afterSaleService: afterSaleService,
		ledgerService:    ledgerService,
		orderService:     orderService,
		paymentService:   paymentService,
		wxpMinaService:   wxpMinaService,
	}
}

// NewContextLogger create a SugaredLogger with contextvalue
func (s *AfterSaleAPIService) NewContextLogger(ctx context.Context) *zap.SugaredLogger {
	return util.NewContextLogger(ctx, s.slog)
}
